/*
 * Copyright (c) 2006-2020, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-05-21     chenhy       the first version
 */
#include "board.h"
#include "adc.h"
#include "uart.h"

void USART1_IRQHandler(void)
{
  rt_interrupt_enter();
  HAL_UART_IRQHandler(&huart1);
  if(__HAL_UART_GET_FLAG(&huart1, UART_FLAG_IDLE) != RESET) {
    __HAL_UART_CLEAR_IDLEFLAG(&huart1);
    HAL_UART_RxCpltCallback(&huart1);
  }
  rt_interrupt_leave();
}

void USART2_IRQHandler(void)
{
  rt_interrupt_enter();
  HAL_UART_IRQHandler(&huart2);
  if(__HAL_UART_GET_FLAG(&huart2, UART_FLAG_IDLE) != RESET) {
    __HAL_UART_CLEAR_IDLEFLAG(&huart2);
    HAL_UART_RxCpltCallback(&huart2);
  }
  rt_interrupt_leave();
}

void USART3_6_IRQHandler(void)
{
  rt_interrupt_enter();
  HAL_UART_IRQHandler(&huart3);
  if(__HAL_UART_GET_FLAG(&huart3, UART_FLAG_IDLE) != RESET) {
    __HAL_UART_CLEAR_IDLEFLAG(&huart3);
    HAL_UART_RxCpltCallback(&huart3);
  }
  rt_interrupt_leave();
}

void DMA1_Channel1_IRQHandler(void)
{
  rt_interrupt_enter();
  HAL_DMA_IRQHandler(huart3.hdmarx);
  rt_interrupt_leave();
}

void DMA1_Channel2_3_IRQHandler(void)
{
  rt_interrupt_enter();
  HAL_DMA_IRQHandler(huart1.hdmarx);
  HAL_DMA_IRQHandler(hadc1.DMA_Handle);
  rt_interrupt_leave();
}

void DMA1_Channel4_5_IRQHandler(void)
{
  rt_interrupt_enter();
  HAL_DMA_IRQHandler(huart2.hdmarx);
  rt_interrupt_leave();
}
